package com.zhuiyun.project.api.poetryAuthor.controller;

import com.zhuiyun.project.annotation.OptLog;
import com.zhuiyun.project.api.poetryAuthor.entity.PoetryAuthor;
import com.zhuiyun.project.api.poetryAuthor.model.PoetryAuthorModel;
import com.zhuiyun.project.api.poetryAuthor.service.PoetryAuthorService;
import com.zhuiyun.project.common.controller.BaseController;
import com.zhuiyun.project.common.errorCode.CommonException;
import com.zhuiyun.project.common.response.CommonResult;
import com.zhuiyun.project.utils.constants.CommonConstants;
import com.zhuiyun.project.utils.pageUtil.PageRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description TODO  作者管理
 * @Author shy
 * @Date 2023/12/11 8:38
 */
@RestController
@RequestMapping("poetryAuthor")
@Api(tags = "作者管理")
public class PoetryAuthorController extends BaseController {
    @Autowired
    private PoetryAuthorService poetryAuthorService;


    @GetMapping("getAllAuthor")
    public CommonResult GetAllAuthor(){
        return poetryAuthorService.GetAllAuthor();
    }
    /**
     *
     * @Author shy
     * @Date 2023/12/11 13:42 TODO 模糊分页查询作者
      * @param poetryAuthor
     * @return CommonResult
     */
    @GetMapping("listAuthor")
    @OptLog(modular = "作者管理",type = CommonConstants.SELECT,describe = "查询作者")
    @ApiOperation(value = "查询作者")
    public CommonResult ListAuthor(PoetryAuthorModel poetryAuthor, PageRequest pageRequest){
        return poetryAuthorService.ListAuthor(poetryAuthor,pageRequest);
    }
    /**
     *
     * @Author shy
     * @Date 2023/12/11 13:42 TODO 根据Id删除作者
      * @param id
     * @return CommonResult
     */
    @DeleteMapping("deleteAuthor")
    @OptLog(modular = "作者管理",type = CommonConstants.DELETE,describe = "删除作者")
    @ApiOperation(value = "删除作者")
    public CommonResult DeleteAuthor(Integer id){
        return poetryAuthorService.DeleteAuthor(id);
    }
    /**
     *
     * @Author shy
     * @Date 2023/12/11 13:43 TODO 添加作者
      * @param poetryAuthorModel
     * @return CommonResult
     */
    @PostMapping("insertAuthor")
    @OptLog(modular = "作者管理",type = CommonConstants.ADD,describe = "添加诗词")
    @ApiOperation(value = "添加作者")
    public CommonResult InsertAuthor(PoetryAuthorModel poetryAuthorModel) throws CommonException {
        return poetryAuthorService.InsertAuthor(poetryAuthorModel);
    }
    /**
     *
     * @Author shy
     * @Date 2023/12/11 13:44 TODO 修改作者
      * @param poetryAuthorModel
     * @return CommonResult
     */
    @PostMapping("updateAuthor")
    @OptLog(modular = "作者管理",type = CommonConstants.UPDATE,describe = "修改作者")
    @ApiOperation(value = "修改作者")
    public CommonResult UpdateAuthor(PoetryAuthorModel poetryAuthorModel) throws CommonException {
        return poetryAuthorService.UpdateAuthor(poetryAuthorModel);
    }

    /**
     *
     * @Author shy
     * @Date 2023/12/14 10:47 TODO 根据id查询作者
      * @param id
     * @return CommonResult
     */
    @GetMapping("getAuthorById")
    @OptLog(modular = "作者管理",type = CommonConstants.UPDATE,describe = "根据Id查询作者")
    @ApiOperation(value = "根据Id查询作者")
    public CommonResult getAuthorById(Integer id) throws CommonException {
        return poetryAuthorService.getAuthorById(id);
    }
}